<?php
//addColumn
$this->addColumn('in_products', array(  
    'header_css_class' => 'a-center',  
    'type' => 'checkbox', //datetime,date ,number  
    'field_name' => 'in_products', //checkbox name  
    'align' => 'center',  
    'index' => 'type',  
    'values' => array(1), //checked value list  
    'disabled_values' => array(1, 3),  
    'use_index' => true, //checkvalue=type false=pkid  
));

$this->addColumn('status', array(  
    'header'=> Mage::helper('catalog')->__('Status'),  
    'width' => '70px',  
    'index' => 'status',  
    'type'  => 'options',  
    'options' => array('new'=>'待发货','sending'=>'发货中','complete'=>'完成')  
));

$this->addColumn('address', array(  
    'header' => '地址',  
    'width' => '200',  
    'index' => 'address',  
    'renderer' => Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Address  
));

public function render(Varien_Object $row) {
    $text = $row['province'] . $row['city'] . $row['county'] .$row['street'];  
    return $text;
}

$this->addColumn('action', array(  
    'header' => '操作',  
    'width' => '50px',  
    'type' => 'action',  
    'getter' => 'getId', //action['field']的值  
    'actions' => array(  
        array(  
            'caption' => '删除',  
            'url' => array('base' => '*/*/delete', /*'params'=>array('type'=>1)*/), //其他参数  
            'field' => 'order_id',  
            'filter' => array('status' => 'new') //出现的条件  
        )  
    ),  
    'filter' => false,  
    'sortable' => false,  
    'index' => 'stores',  
    'is_system' => true,  
    'renderer' => Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Action  
));  
 

//自定义搜索
protected function _setFilterValues($data) {
    if(isset($data['name'])):
        $entityids = array();
        $item_collection = Mage::getSingleton('sales/order_item')->getCollection()
            ->addFieldToFilter('name', array('like' => '%' . $data['name'] . '%'));
        foreach ($item_collection as $key => $item) {
            $entityids[] = $item->getOrderId();
        }    
    //echo $entityids->getSelect();
    foreach ($this->getColumns() as $columnId => $column) {  
        if ($columnId == 'name' && isset($data[$columnId]) && strlen($data[$columnId]) > 0) {  
            $this->getCollection()->addFieldToFilter('entity_id', array('in' => $entityids));
            $column->getFilter()->setValue($data[$columnId]);  
            continue;
        }
        if (isset($data[$columnId]) && (!empty($data[$columnId]) || strlen($data[$columnId]) > 0) && $column->getFilter()) {  
            $column->getFilter()->setValue($data[$columnId]);  
            $this->_addColumnFilterToCollection($column);  
        }

    }
    endif; 
    return $this;  
} 




?>